package com.fr.dialog.core;

import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.io.Serializable;

public class VerticalFlowLayout
  implements LayoutManager, Serializable
{
  public static final int TOP = 0;
  public static final int CENTER = 1;
  public static final int BOTTOM = 2;
  int alisgn;
  int newAlign;
  int hgap;
  int vgap;

  public VerticalFlowLayout()
  {
    this(1, 5, 5);
  }

  public VerticalFlowLayout(int paramInt)
  {
    this(paramInt, 5, 5);
  }

  public VerticalFlowLayout(int paramInt1, int paramInt2, int paramInt3)
  {
    this.hgap = paramInt2;
    this.vgap = paramInt3;
    setAlignment(paramInt1);
  }

  public int getAlignment()
  {
    return this.newAlign;
  }

  public void setAlignment(int paramInt)
  {
    this.newAlign = paramInt;
  }

  public int getHgap()
  {
    return this.hgap;
  }

  public void setHgap(int paramInt)
  {
    this.hgap = paramInt;
  }

  public int getVgap()
  {
    return this.vgap;
  }

  public void setVgap(int paramInt)
  {
    this.vgap = paramInt;
  }

  public void addLayoutComponent(String paramString, Component paramComponent)
  {
  }

  public void removeLayoutComponent(Component paramComponent)
  {
  }

  public Dimension preferredLayoutSize(Container paramContainer)
  {
    synchronized (paramContainer.getTreeLock())
    {
      Dimension localDimension1 = new Dimension(0, 0);
      int i = paramContainer.getComponentCount();
      int j = 1;
      for (int k = 0; k < i; ++k)
      {
        Component localComponent = paramContainer.getComponent(k);
        if (localComponent.isVisible())
        {
          Dimension localDimension2 = localComponent.getPreferredSize();
          localDimension1.width = Math.max(localDimension1.width, localDimension2.width);
          if (j != 0)
            j = 0;
          else
            localDimension1.height += this.vgap;
          localDimension1.height += localDimension2.height;
        }
      }
      Insets localInsets = paramContainer.getInsets();
      localDimension1.width += localInsets.left + localInsets.right + this.hgap * 2;
      localDimension1.height += localInsets.top + localInsets.bottom + this.vgap * 2;
      return localDimension1;
    }
  }

  public Dimension minimumLayoutSize(Container paramContainer)
  {
    synchronized (paramContainer.getTreeLock())
    {
      Dimension localDimension1 = new Dimension(0, 0);
      int i = paramContainer.getComponentCount();
      for (int j = 0; j < i; ++j)
      {
        Component localComponent = paramContainer.getComponent(j);
        if (localComponent.isVisible())
        {
          Dimension localDimension2 = localComponent.getMinimumSize();
          localDimension1.width = Math.max(localDimension1.width, localDimension2.width);
          if (j > 0)
            localDimension1.height += this.vgap;
          localDimension1.height += localDimension2.height;
        }
      }
      Insets localInsets = paramContainer.getInsets();
      localDimension1.width += localInsets.left + localInsets.right + this.hgap * 2;
      localDimension1.height += localInsets.top + localInsets.bottom + this.vgap * 2;
      return localDimension1;
    }
  }

  private void moveComponents(Container paramContainer, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6, boolean paramBoolean)
  {
    int i;
    synchronized (paramContainer.getTreeLock())
    {
      switch (this.newAlign)
      {
      case 0:
        paramInt2 += ((paramBoolean) ? 0 : paramInt4);
        break;
      case 1:
        paramInt2 += paramInt4 / 2;
        break;
      case 2:
        paramInt2 += ((paramBoolean) ? paramInt4 : 0);
      }
      for (i = paramInt5; i < paramInt6; ++i)
      {
        Component localComponent = paramContainer.getComponent(i);
        if (localComponent.isVisible())
        {
          if (paramBoolean)
            localComponent.setLocation(paramInt1 + (paramInt3 - localComponent.getWidth()) / 2, paramInt2);
          else
            localComponent.setLocation(paramInt1 + (paramInt3 - localComponent.getWidth()) / 2, paramContainer.getHeight() - paramInt2 - localComponent.getHeight());
          paramInt2 += localComponent.getHeight() + this.vgap;
        }
      }
    }
  }

  public void layoutContainer(Container paramContainer)
  {
    synchronized (paramContainer.getTreeLock())
    {
      Insets localInsets = paramContainer.getInsets();
      int i = paramContainer.getHeight() - localInsets.top + localInsets.bottom + this.vgap * 2;
      int j = paramContainer.getComponentCount();
      int k = localInsets.left + this.hgap;
      int l = 0;
      int i1 = 0;
      int i2 = 0;
      boolean bool = paramContainer.getComponentOrientation().isLeftToRight();
      for (int i3 = 0; i3 < j; ++i3)
      {
        Component localComponent = paramContainer.getComponent(i3);
        if (localComponent.isVisible())
        {
          Dimension localDimension = localComponent.getPreferredSize();
          localComponent.setSize(localDimension.width, localDimension.height);
          if ((l == 0) || (l + localDimension.height <= i))
          {
            if (l > 0)
              l += this.vgap;
            l += localDimension.height;
            i1 = Math.max(i1, localDimension.width);
          }
          else
          {
            moveComponents(paramContainer, k, localInsets.top + this.vgap, i1, i - l, i2, i3, bool);
            l = localDimension.height;
            k += this.hgap + i1;
            i1 = localDimension.width;
            i2 = i3;
          }
        }
      }
      moveComponents(paramContainer, k, localInsets.top + this.vgap, i1, i - l, i2, j, bool);
    }
  }

  public String toString()
  {
    String str = "";
    switch (this.newAlign)
    {
    case 0:
      str = ",align=top";
      break;
    case 1:
      str = ",align=center";
      break;
    case 2:
      str = ",align=bottom";
    }
    return super.getClass().getName() + "[hgap=" + this.hgap + ",vgap=" + this.vgap + str + "]";
  }
}